{extend name="foxcms" /}

{block name="css"}

{/block}

{block name="body"}
<div class="foxcms-content-inner">
    <!-- page content -->
    <div class="contact-way-content">
        <div class="section section-panel">
            <div class="section-title">添加链接</div>
            <div class="section-main">

                <div class="section-main-item">
                    <div class="foxui-input-group">
                        <div class="input-label">
                            <label class="foxui-required">TAG标签组：</label>
                        </div>
                        <div class="input-box">
                            <div class="foxui-select">
                                <div class="foxui-select-handle foxui-select-icon">
                                    <input class="foxui-select-input" readonly="readonly" name="tag_group" placeholder="请选择" value="{$tagGroupList[0]['name']}" data-id="{$tagGroupList[0]['id']}" />
                                </div>
                                <div class="foxui-select-menu">
                                    <ul class="foxui-select-slide">
                                        {foreach $tagGroupList as $key=>$vo }
                                        <li class="foxui-select-item" data-id="{$vo.id}">{$vo.name}</li>
                                        {/foreach}
                                    </ul>
                                </div>
                            </div>

                        </div>
                    </div>
                </div>

                <div class="section-main-item">
                    <div class="foxui-input-group">
                        <div class="input-label">
                            <label class="foxui-required">Tag标签列表：</label>
                        </div>
                        <div class="input-box">
                            <div class="foxui-textarea">
                                <textarea name="tags" style="height: 180px;" autocomplete="off" rows="2" placeholder="一行代表一个Tag标签"></textarea>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="section-main-item">
                    <div class="foxui-input-group">
                        <div class="input-label">
                            <label class="foxui-required">是否常用：</label>
                        </div>
                        <div class="input-box is_used">
                            <div class="foxui-radio-group">
                                <div class="foxui-radio is-checked">
                                    <span class="foxui-radio-input">
                                        <i class="foxui-radio-icon"></i>
                                        <input type="radio" value="1"/>
                                    </span>
                                    <span class="foxui-radio-label">是</span>
                                </div>
                                <div class="foxui-radio">
                                    <span class="foxui-radio-input">
                                        <i class="foxui-radio-icon"></i>
                                        <input type="radio" value="0"/>
                                    </span>
                                    <span class="foxui-radio-label">否</span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

{include file="footed-copy"/}
<div class="foxcms-content-footer">
    <button class="is-long foxui-size-small foxui-solid-primary" id="save">保存</button>
</div>
{/block}

{block name="js"}

<script>


    //保存
    $('#save').click(function (){

        let tag_group_id = $('input[name="tag_group"]').attr('data-id');
        if(tag_group_id == "" || !tag_group_id){
            foxui.message({
                type:'warning',
                text:'请选择TAG标签组,如果没有请先添加'
            })
            return;
        }

        //Tag标签列表
        let tags = $('textarea[name="tags"]').val();
        if(tags == "" || !tags){
            foxui.message({
                type:'warning',
                text:'请输入Tag标签'
            })
            return;
        }
        //是否常用
        let is_used = $('.is_used .is-checked input').val();
        let datas ={tags, is_used, tag_group_id};

        foxui.dialog({
            title: '保存',
            content: '您确定要保存吗',
            cancelText: '取消',
            confirmText: '保存',
            confirm: function (callback) {
                $.ajax({
                    type: "post",
                    url: 'add',
                    dataType: "json",
                    data: datas,
                    success: function (res) {
                        if (res.code == 1) {
                            foxui.message({
                                type:'success',
                                text:res.msg
                            })
                            window.location.href=document.referrer;//返回并且刷新
                        } else {
                            foxui.message({
                                type:'danger',
                                text:res.msg
                            })
                        }
                    }, error: function (res) {
                        foxui.message({
                            type:'danger',
                            text:res.msg
                        })
                    }
                });
                callback();
            },
            cancel: function () {
                foxui.message({
                    type:'warning',
                    text:'取消操作'
                })
            },
        });

    })


</script>
{/block}
